home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / prog_c / cuj0696.zip / DWYER.ZIP / GAP.TST / GENGAPDA.C < prev    next >
C/C++ Source or Header  |  1996-02-12  |  1KB  |  55 lines

  1. /* ============ */
  2. /* gengapda.c    */
  3. /* ============ */
  4. #include <miscdefs.h>
  5. #include <gapdefs.h>
  6.  
  7. #include <string.h>
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10.  
  11. /* ==================================================================== */
  12. /* GenGapData - Generates Data Relating to One Gap            */
  13. /* ==================================================================== */
  14. /* -------------------------------------------------------------------- */
  15. /* This code reflects the algorithm given by D. E. Knuth, The Art of    */
  16. /* Computer Programming, Vol. 2, Seminumerical Algorithms, Second Ed.,    */
  17. /* Addison-Wesley, Reading (1981), pp. 60-61, Algorithm G, steps G2-G4.    */ 
  18. /* -------------------------------------------------------------------- */
  19. UINT
  20. GenGapData(GAP_DATA_STRU * GapData)
  21. {
  22.     int     Next, GapSize, NumGen;
  23.  
  24.     GapSize = 0;
  25.     NumGen  = 0;
  26.  
  27.     do
  28.     {
  29.     Next = GapData->RandFun();
  30.  
  31.     ++NumGen;
  32.  
  33.     if ((UINT)Next >= GapData->LoGapInt && (UINT)Next < GapData->HiGapInt)
  34.     {
  35.         break;
  36.     }
  37.     ++GapSize;
  38.     }
  39.     while (NumGen <= GapData->MaxGenPerGap);
  40.  
  41.     if (NumGen <= GapData->MaxGenPerGap)
  42.     {
  43.     GapData->CallStatusOK = TRUE;
  44.     }
  45.     else
  46.     {
  47.     GapData->CallStatusOK = FALSE;
  48.  
  49.     fprintf(stderr,
  50.         "GenGapData(): Failed to Detect a Gap\n");
  51.     }
  52.  
  53.     return(GapSize);
  54. }
  55.